/*
 * ShowStringWidget.cpp
 *
 *  Created on: 2015-8-14
 *      Author: 10095427
 */

#include "ShowStringWidget.h"

USING_NS_CC;

#define NUMX   0
#define NUMY   0
#define SHOWTIME 0.5
#define YPADMAX  20
#define NORMAL_FONTSIZE   25
#define STRONG_FONTSIZE   35
#define TEXT_FONTNAME     "arial"

ShowStringWidget::ShowStringWidget()
:strLabel(NULL)
,lastTime(0)
{
}

bool ShowStringWidget::init()
{
    if (!Layer::init()) {
        return false;
    }

    labelInit();
    scheduleUpdate();

    return true;
}

void ShowStringWidget::labelInit()
{
	strLabel = LabelTTF::create("0", TEXT_FONTNAME, NORMAL_FONTSIZE);
	strLabel->setAnchorPoint(Point(0, 0));
	strLabel->setPosition(NUMX, NUMY);
	strLabel->setColor(Color3B::GREEN);
    addChild(strLabel);
}

void ShowStringWidget::setText(const std::string &text)
{
	strLabel->setString(text);
	strLabel->setPosition(NUMX-strLabel->getContentSize().width/2,NUMY);
}

void ShowStringWidget::setTextColor(Color3B color)
{
	strLabel->setColor(color);
}

void ShowStringWidget::update(float dt)
{
    if(lastTime < SHOWTIME){
        lastTime += dt;
        strLabel->setPosition(strLabel->getPosition().x,YPADMAX*lastTime/SHOWTIME);
    }else{
        this->removeFromParent();
    }
}
